import { exportReport } from "../reportBuilder/service"; // 报告导出
import { templateExport, templateImport } from "../../services/annotaionAnalysis"; // 附注导出，
import { request } from 'umi';
import { exportDraft } from "../../pages/AuditPaper/PaperTable/components/ExportTemplate/service"; // 导出底稿
import { exportFjs } from "../../pages/AuditAttach/service"; // 导出附件
import { getDateList, DateUpdate, PeriodUpdate } from '@/pages/home/components/SetDataGrid/service';
import getApiData, { getNestApiData, onlineGetApiData } from "@/services/cpasRequest";
import { updateReport_setting_column } from '@/pages/batchSettings/service';
import { getLeftTreeList } from "../reportAnalysis/tab1/server";
import { formatterChinaTime } from '@/utils';
import { getPaperList } from "../AuditPaper/service";
import PubSub from 'pubsub-js'
// import { getPhaseTreeBatchReplace} from "../AuditPaper/PaperTable/service";
enum leftTitleList {
  zcfb = 1,
  dgfj = 2,
  auditAdjust = 3,
  notes = 4,
  report = 5,
  SATURDAY = 6
}
/**
 *
 * @param savepath    保存路径
 * @param zcbfid   项目ID
 * @param type    导出类型
 * @param Zcbfinfo   项目名称
 * @param dg 底稿
 * @param dgfj 附件
 * @param adjust 调整分录
 * @param notes 附注及试算
 * @param report 报告
 * @param dataId 年份
 */

export async function exportTemplate(savepath: string, zcbfid: string, sjxmbh: string, type: {
  items: any;
  isselected: any;
  selected: any; id: number
}[], Zcbfinfo: { projectInfo: object, accountDate: [] }, dg: [], dgfj: [], dglinkfj: [], adjust: [], notes: [], report: [], dataId: string, Trial: [], accountDatelist: [], accountDate: [], accountDateSet: []) {
  // 导出底稿
  // console.log(savepath, zcbfid, type, Zcbfinfo, dg, dgfj, adjust, notes, report, Trial, accountDatelist,dglinkfj)
  // 临时目录
  //@ts-ignore
  let tempPath = window.main.mainObject.getAppPath() + "\\Temp\\";
  //@ts-ignore
  if (window.main.mainObject.fileExists(tempPath)) {
    //@ts-ignore
    window.main.mainObject.deleteFolder(tempPath, false)
  }
  //@ts-ignore
  window.main.mainObject.createDirs(`${tempPath}`)

  // 过滤掉没有选中的或者没有项目信息的
  let configExportTitle = type.filter(a => a.selected && a.isselected);
  configExportTitle.map(a => a.items ? a.items = a.items.filter((b: { selected: any; isselected: any; }) => b.selected && b.isselected) : [])


  // 生成配置文件 到临时目录,并创建了目录

  //@ts-ignore
  let projectPathInfo = window.main.mainObject.getAppPath() + "\\ProjectData\\" + `${sjxmbh}\\${zcbfid}\\`;
  try {
    let promise_arg_arr = []
    for (let i of configExportTitle) {


      if (i.id == leftTitleList.dgfj) {
        if (dg.length || dgfj.length) {
          PubSub.publish('call_progress', { data: 1, msg: "底稿附件导出中", count: configExportTitle.length })
        }

        // 导出底稿
        if (dg.length) {
          //@ts-ignore
          window.main.mainObject.createDirs(`${tempPath}底稿`)
          for await (const iterator of dg) {
            //@ts-ignore
            window.main.mainObject.copyFile(`${projectPathInfo}\\底稿\\${iterator.dgnd}_${iterator.name}`, `${tempPath}底稿\\${iterator.dgnd}_${iterator.name}`)
          }
          await dgfjExport({ targetDir: `${tempPath}`, data: dg.map((a: any) => a.id), dbName: zcbfid, operate: "export", type: "dg",dataids: [...new Set(dg.map((a: any) => a.dgnd))]  })
          // promise_arg_arr.push(dgfjExport({ targetDir: `${tempPath}`, data: dg.map((a: any) => a.id), dbName: zcbfid, operate: "export", type: "dg" dgnd }))
          if (dglinkfj.length) {
            //@ts-ignore
            window.main.mainObject.createDirs(`${tempPath}附件`)
            for await (const iterator of dglinkfj) {
              //@ts-ignore
              window.main.mainObject.copyFile(`${projectPathInfo}\\底稿附件\\${iterator.fjName}${iterator.fjlx}`, `${tempPath}附件\\${iterator.fjName}${iterator.fjlx}`)
            }

            await dgfjExport({ targetDir: `${tempPath}`, data: dglinkfj.map((a: any) => a.fjid), dbName: zcbfid, operate: "export", type: "fj" })

            // promise_arg_arr.push(dgfjExport({ targetDir: `${tempPath}`, data: dglinkfj.map((a: any) => a.fjid), dbName: zcbfid, operate: "export", type: "fj" }))
          }
        }
        if (dgfj.length) {
          //@ts-ignore
          window.main.mainObject.createDirs(`${tempPath}附件`)
          for await (const iterator of dgfj) {
            //@ts-ignore
            window.main.mainObject.copyFile(`${projectPathInfo}\\底稿附件\\${iterator.name}`, `${tempPath}附件\\${iterator.name}`)
          }
          await dgfjExport({ targetDir: `${tempPath}`, data: dgfj.map((a: any) => a.id), dbName: zcbfid, operate: "export", type: "fj" })
          // promise_arg_arr.push(dgfjExport({ targetDir: `${tempPath}`, data: dgfj.map((a: any) => a.id), dbName: zcbfid, operate: "export", type: "fj" }))
        }


      } else if (i.id == leftTitleList.auditAdjust) {
        // 导出
        if (adjust.length > 0) {
          PubSub.publish('call_progress', { data: 1, msg: "调整分录导出中", count: configExportTitle.length })
          await accountAdjustExport({ targetDir: `${tempPath}`, data: adjust.filter((a: any) => a.selected).map((a: any) => a.BillID), dbName: zcbfid, operate: "export" })
          // promise_arg_arr.push(()=> accountAdjustExport({ targetDir: `${tempPath}`, data: adjust.filter((a: any) => a.selected).map((a: any) => a.BillID), dbName: zcbfid, operate: "export" }))

        }
      }
      else if (i.id == leftTitleList.notes) {
        if (notes.length || Trial.length) {
          PubSub.publish('call_progress', { data: 1, msg: "附注及试算导出中", count: configExportTitle.length })
        }

        // 导出附注
        if (notes.length) {
          await templateExport({ type: "ds", dbName: zcbfid, dataId: dataId, tableNames: notes.map((a: any) => a.name), templateFile: `${tempPath}Auditdg.db` })
          // promise_arg_arr.push(templateExport({ type: "ds", dbName: zcbfid, dataId: dataId, tableNames: notes.map((a: any) => a.name), templateFile: `${tempPath}${zcbfid}.db` }))

        }
        accountDateSet = (await getDateList({ zcbfid: zcbfid }))
        if (Trial.filter((a: any) => a.selected && a.isselected).length) {
          let arr: any[] = []
          Trial.filter((a: any) => a.selected).map(async (a: any) => {


            if (a.selected && a.name == "未审财务报表") {
              let noAudit = ['未审财务报表-负债表', '未审财务报表-利润表', '未审财务报表-现金流补充资料表', "未审财务报表-现金流量表", "未审财务报表-资产表"]
              arr = noAudit

            }
            if (a.selected && a.name == "审定财务报表") {
              let adiut = ['审定财务-负债表',
                '审定财务-利润表',
                '审定财务-所有者权益变动表_本年',
                '审定财务-所有者权益变动表_上年',
                '审定财务-现金流补充资料表',
                '审定财务-资产减值准备情况表',
                '审定财务-现金流量表',
                '审定财务-资产表',]
              arr = [...arr, ...adiut]

            }
            if (a.selected && a.name == "试算平衡表") {
              let shisuandiut: string[] = []

              // console.log(accountDateSet, "accountDatelist")

              accountDateSet.forEach((a: any) => {
                console.log(a, "a")

                shisuandiut.push(`${a.Data_ID}_试算平衡-负债表_期初`)
                shisuandiut.push(`${a.Data_ID}_试算平衡-负债表_期末`)
                shisuandiut.push(`${a.Data_ID}_试算平衡-利润表_本期`)
                shisuandiut.push(`${a.Data_ID}_试算平衡-利润表_上期`)
                shisuandiut.push(`${a.Data_ID}_试算平衡-所有者权益变动表_本年`)
                shisuandiut.push(`${a.Data_ID}_试算平衡-所有者权益变动表_上年`)
                shisuandiut.push(`${a.Data_ID}_试算平衡-现金补充资料表_本期`)
                shisuandiut.push(`${a.Data_ID}_试算平衡-现金补充资料表_上期`)
                shisuandiut.push(`${a.Data_ID}_试算平衡-现金流量表_本期`)
                shisuandiut.push(`${a.Data_ID}_试算平衡-现金流量表_上期`)
                shisuandiut.push(`${a.Data_ID}_试算平衡-资产表_期初`)
                shisuandiut.push(`${a.Data_ID}_试算平衡-资产表_期末`)
                shisuandiut.push(`${a.Data_ID}_试算平衡-资产减值准备情况表`)
              })

              arr = [...arr, ...shisuandiut]

            }


          })
          if (arr.length) {
            await templateExport({ type: "fs", dbName: zcbfid, dataId: dataId, tableNames: arr, templateFile: `${tempPath}Auditdg-fs.db` })
            // promise_arg_arr.push( templateExport({ type: "fs", dbName: zcbfid, dataId: dataId, tableNames: arr, templateFile: `${tempPath}${zcbfid}-fs.db` }))

          }

        }

      } else if (i.id == leftTitleList.report && i.selected) {
        // 导出报告
        //支持单个报告导出
        // 新增单个报告导入接口
        // 循环
        if (report.length) {
          PubSub.publish('call_progress', { data: 1, msg: "报告导出中", count: configExportTitle.length })
        }

        for (let j of report) {

          await exportReport({ projectId: sjxmbh, partId: zcbfid, version: j, targetDir: `${tempPath}报告\\${j}\\`, isTemplate: false })
          // promise_arg_arr.push( exportReport({ projectId: sjxmbh, partId: zcbfid, version: j, targetDir: `${tempPath}报告\\${j}\\`, isTemplate: false }))
        }

      } else if (i.id == leftTitleList.zcfb && i.selected) {

        // 导出组成部分
        if (i.items.filter((a: any) => a.selected && a.id == 12).length == 1) {
          PubSub.publish('call_progress', { data: 1, msg: "基础部分导出中", count: configExportTitle.length })
          await dateSetExport({ targetDir: `${tempPath}`, data: [{ tableName: 'report_setting_column' }, { tableName: "period_settings" }], dbName: zcbfid, operate: "export", sqlLiteDbName: `DateSet.db` })
        }

      }
    }
    // await Promise.all(promise_arg_arr).then(async (res: any) => {
    //   console.log(res, "res")
    // }).catch(       (err: any) => {
    //   console.log(err, "err")
    // })
    //@ts-ignore
    let config = await window.main.mainObject.saveContentToFile({ exportFirstIndex: configExportTitle, exportNoteIndex: notes, dgfj: dgfj, exportdgIndex: dg, dglinkfj: dglinkfj, report: report, zcbfid: zcbfid, sjxmbh: sjxmbh, Zcbfinfo: Zcbfinfo, adjust: adjust, Trial: Trial, accountDatelist, accountDate: accountDate, accountDateSet: accountDateSet,dataId:dataId }, `${tempPath}config.json`)
    return true
  } catch (error) {

    console.log(error)
    return false
  }

  // 压缩文
}

/**
 *
 * @param zcbfid
 * @param type
 * @param Zcbfinfo
 * @param dg
 * @param dgfj
 * @param adjust
 * @param notes
 * @param report
 * @param dataId
 */
export async function importTemplate(zcbfid: string, sjxmbh: string, type: {
  items: any;
  isselected: boolean;
  selected: boolean; id: number
}[], Zcbfinfo: {
  accountDateSet: any;
  accountDate: any; zcbfinfo: { ReceivePerson: string, AuditReportDate: string }
}, dg: [{dgnd:string,name:string}], dgfj: [{name:string}], dgfilink: [{fjName:string,fjlx:string}], adjust: [], notes: [], report: [], dataId: string, Trial: [], accountDateSet: [],
  package_zcbfid: string, package_sjxmbh: string
) {
  // 导入解压，获取压缩文件，进行解压
  // 先渲染config
  // 更具用户的先择，记住选择，调用各个部分的导入接口

  //@ts-ignore
  let tempPath = window.main.mainObject.getAppPath() + "\\Temp\\";
  //@ts-ignore
  let projectPath = window.main.mainObject.getAppPath() + "\\ProjectData\\" + `${sjxmbh}\\${zcbfid}\\报告\\`;

  //@ts-ignore
  let projectPathInfo = window.main.mainObject.getAppPath() + "\\ProjectData\\" + `${sjxmbh}\\${zcbfid}\\`;
  // console.log(accountDateSet,"accountDateSet")
  let configExportTitle = type.filter(a => a.selected && a.isselected);
  // configExportTitle.map(a=> a.items? a.items= a.items.filter( (b: { selected: any; isselected: any; })=>b.selected && b.isselected):[])

  try {
    let error_file:any = []
    for (let i of configExportTitle) {
      if (i.id == leftTitleList.zcfb) {
          PubSub.publish('call_progress_import', { data: 1, msg: "组成部分导入中", count: configExportTitle.length })
        for (let j of i.items) {
          if (Zcbfinfo.zcbfinfo?.ReceivePerson && j.id == 11 && j.selected) {
            let data = <any>[];
            data.push({
              rowState: "update",
              ReceivePerson: Zcbfinfo.zcbfinfo.ReceivePerson,
              AuditReportDate: Zcbfinfo.zcbfinfo.AuditReportDate,
              where: {
                zcbfID: zcbfid,
              }
            })
            await getApiData("sqlApi.update", {
              name: "SJXM_ZCBF",
              rows: data
            });
          }
          if (j.id == 12 && j.selected) {
            await dateSetExport({ targetDir: `${tempPath}`, data: [{ tableName: 'report_setting_column' }, { tableName: "period_settings" }], dbName: zcbfid, operate: "import", sqlLiteDbName: `DateSet.db` })
          }
        }

      } else if (i.id == leftTitleList.auditAdjust && i.selected) {
        //
        if (adjust.length > 0) {
          PubSub.publish('call_progress_import', { data: 1, msg: "审计调整导入中", count: configExportTitle.length })
          await accountAdjustExport({ targetDir: `${tempPath}`, data: adjust.filter((a: any) => a.selected).map((a: any) => a.BillID), dbName: zcbfid, operate: "import" })
        }
      } else if (i.id == 5 && i.selected) {
        PubSub.publish('call_progress_import', { data: 1, msg: "报告导入中", count: configExportTitle.length })
        // 导出报告
        //支持单个报告导出
        // 新增单个报告导入接口
        // console.log("导出报告", report);
        for (let j of report) {
          // await exportReport({ projectId: zcbfid, partId: zcbfid, version: j , targetDir: `${tempPath}报告\\`, isTemplate: false })
          // 没有目录还要新建
          try {
            //@ts-ignore
            window.main.mainObject.createDirs(`${projectPath}${j}`)
            console.log(`${tempPath}${j}: 报告导入`)
            //@ts-ignore
            window.main.mainObject.copyFile(`${tempPath}报告\\${j}\\报告附注.docx`, `${projectPath}${j}\\报告附注.docx`)
            //@ts-ignore
            window.main.mainObject.copyFile(`${tempPath}报告\\${j}\\报告正文.docx`, `${projectPath}${j}\\报告正文.docx`)
            //@ts-ignore
            window.main.mainObject.copyFile(`${tempPath}报告\\${j}\\财务报表.xlsx`, `${projectPath}${j}\\财务报表.xlsx`)
            if (j !== 'Generated') {
              //@ts-ignore
               window.main.mainObject.copyFile(`${tempPath}报告\\${j}\\Note${j}.json`, `${projectPath}${j}\\Note${j}.json`)
            }

          } catch (error) {
            error_file.push(`${ j === 'Generated'?'当前':j}版本的报告导入失败,`)
            console.log(error)

          }
        }

      } else if (i.id == leftTitleList.notes && i.selected) {
        if (notes && notes.length) {
          PubSub.publish('call_progress_import', { data: 42, msg: "附注导入中", count: configExportTitle.length })
          await templateImport({ type: "ds", dbName: zcbfid, dataId: dataId, tableNames: notes.map((a: any) => a.name), templateFile: `${tempPath}Auditdg.db`, opt: { duplicate: "cover" } })
        }
        //Trial 判断是否选中，期间日期
        await TrialImportExport({ zcbfid: zcbfid, dataId: dataId, tempPath: tempPath, accountDatelist: accountDateSet, Trial: Trial, configExportTitleLength: configExportTitle.length })

      } else if (i.id === leftTitleList.dgfj && i.selected) {

        PubSub.publish('call_progress_import', { data: 1, msg: "底稿附件导入中", count: configExportTitle.length })
        if (dg.length) {
          // db
          await dgfjExport({ targetDir: `${tempPath}`, data: dg.map((a: any) => a.id), dbName: zcbfid, operate: "import", type: "dg",dataids: [...new Set(dg.map((a: any) => a.dgnd))] })
          //@ts-ignore
          window.main.mainObject.createDirs(`${projectPathInfo}底稿`)

          //@ts-ignore
          for await (const iterator of dg) {
            try {
              //@ts-ignore
              window.main.mainObject.copyFile(`${tempPath}底稿\\${iterator.dgnd}_${iterator.name}`, `${projectPathInfo}\\底稿\\${iterator.dgnd}_${iterator.name}`)
            } catch (error) {
              error_file.push(`底稿：${iterator.dgnd}_${iterator.name}导入失败,`)
            }
          }
          if (dgfilink.length) {
            //@ts-ignore
            window.main.mainObject.createDirs(`${projectPathInfo}底稿附件`)
            //@ts-ignore
            for await (const iterator of dgfilink) {
              try {
                 //@ts-ignore
                window.main.mainObject.copyFile(`${tempPath}附件\\${iterator.fjName}${iterator.fjlx}`, `${projectPathInfo}底稿附件\\${iterator.fjName}${iterator.fjlx}`)

              } catch (error) {
                error_file.push(`附件：${iterator.fjName}${iterator.fjlx}导入失败,`)
              }
                         }
            await dgfjExport({ targetDir: `${tempPath}`, data: dgfilink.map((a: any) => a.fjid), dbName: zcbfid, operate: "import", type: "fj" })
          }
        }

        if (dgfj.length) {
          //await  exportFjs(zcbfid,zcbfid,  dgfj.map((a:any)=>a.name),`${tempPath}附件\\`)
          //db
          await dgfjExport({ targetDir: `${tempPath}`, data: dgfj.map((a: any) => a.id), dbName: zcbfid, operate: "import", type: "fj" })
        }

        //@ts-ignore
        window.main.mainObject.createDirs(`${projectPathInfo}底稿附件`)
        for (const iterator of dgfj) {
          try {
             //@ts-ignore
             window.main.mainObject.copyFile(`${tempPath}附件\\${iterator.name}`, `${projectPathInfo}底稿附件\\${iterator.name}`)

          } catch (error) {
            error_file.push(`附件：${iterator.name}导入失败,`)
          }

        }

      }
    }
    if (error_file.length) {
      return error_file
    } else {
      return true;
    }


  } catch (error) {
    console.log(error)
    return false
  }
}


export async function zip(params: any) {
  try {
    const res = await request(`/cpasApi/project/zip`, {
      method: "POST",
      data: params
    });
    return res;
  } catch (error) {
    return Promise.resolve({ data: error, ok: false, code: 100000 });
  }
}


/**
 *
 * @param params {object}src(压缩包),targetDir 目标文件夹
 * @returns
 */
export async function unzip(params: any) {
  try {
    const res = await request(`/cpasApi/project/unzip`, {
      method: "POST",
      data: params
    });
    return res;
  } catch (error) {
    return Promise.resolve({ data: error, ok: false, code: 100000 });
  }
}


export async function accountAdjustExport(params: any) {
  try {
    const res = await request(`/cpasApi/project/result/accountAdjust/import/export`, {
      method: "POST",
      data: params
    });
    return res;
  } catch (error) {
    return Promise.resolve({ data: error, ok: false, code: 100000 });
  }
}


export async function dateSetExport(params: any) {
  try {
    const res = request(`/cpasApi/project/result/dateSet/export`, {
      method: "POST",
      data: params
    });
    return res;
  } catch (error) {
    return Promise.resolve({ data: error, ok: false, code: 100000 });
  }
}
export async function dgfjExport(params: any) {
  try {
    const res = await request(`/cpasApi/project/result/dgfj/import/export`, {
      method: "POST",
      data: params
    });
    return res;
  } catch (error) {
    return Promise.resolve({ data: error, ok: false, code: 100000 });
  }
}


export async function getAccountAdujustList(params: any) {
  try {
    const res = await getApiData("account.adjustingEntry.Bill.getDataList", params);
    return res;
  } catch (error) {
    return Promise.resolve({ data: error, ok: false, code: 100000 });
  }
}


export async function getDesignTabelEditDate(params: any) {
  try {
    const res = await getApiData("disclosure.editdate", params);
    return res;
  } catch (error) {
    return Promise.resolve({ data: error, ok: false, code: 100000 });
  }
}


export async function getAccountAdujustIsSelect(params: any) {
  try {
    const res = await request("/cpasApi/project/result/accountAdjust/IsSelect", {
      method: "POST",
      data: params
    });
    return res;
  } catch (error) {
    return Promise.resolve({ data: error, ok: false, code: 100000 });
  }
}



// 导出取最新的编辑时间

export async function getDesignTabelEditDateCompare(params: any) {
  // 获取节点编辑时间
  let note = await getLeftTreeList(params.zcbfid, params.sjnd)
  // 表编辑时间
  let DesignTabelEditDate = params.table_list
  // console.log(DesignTabelEditDate,"DesignTabelEditDate",note)

  if (note.length && DesignTabelEditDate.length) {
    note = note.map((a: any) => {
      let date = DesignTabelEditDate.filter((b: any) => a.id === b.tid)
      let editDate = null
      if (date.length) {
        if (date[0].editDate) {
          editDate = formatterChinaTime(date[0].editDate)
        }
        if (a.editDate) {
          editDate = formatterChinaTime(a.editDate)
        }
        if (date[0].editDate && a.editDate && (new Date(formatterChinaTime(date[0].editDate))) >= (new Date(formatterChinaTime(a.editDate)))) {
          // console.log('a.editDate',formatterChinaTime(a.editDate),date[0].editDate, (new Date(date[0].editDate))> (new Date(formatterChinaTime(a.editDate))))
          editDate = formatterChinaTime(date[0].editDate)
        }
        if (date[0].editDate && a.editDate && (new Date(formatterChinaTime(date[0].editDate))) < (new Date(formatterChinaTime(a.editDate)))) {
          editDate = formatterChinaTime(a.editDate)
        }
      }

      // console.log(editDate,date[0].editDate,a.editDate, "111", formatterChinaTime(date[0].editDate))
      return { name: a.title, id: a.id, selected: true, pid: a.pid, editDate: editDate, dataId: a.dataId,isselected:true }
    })
  }
  return note
}

export async function getdgTreeList(dbName: string) {


  let dglist = (await getPaperList({ dbname: dbName, zcbfid: dbName, sjjd: "" })).data.filter((a: { dgzt: number; }) => a.dgzt > 0 && a.dgzt < 201)
  if (dglist.length) {
    let res = dglist.map((a: any) => {
      return { name: a.dgmc + a.dglx, editDate: a.editDate, editUser: a.editUser, id: a.dgid, dgnd: a.dgnd }
    })
    return res
  } else {
    return []
  }


}

export async function getdgfjList(params: { dbname: string, dgid: string }) {


  try {
    const res = await request("/cpasApi/project/result/dgfj/list", {
      method: "POST",
      data: params
    });
    if (res.ok) {
      return res.data
    } else {
      return []
    }
    return res;

  } catch (error) {
    return Promise.resolve({ data: error, ok: false, code: 100000 });
  }


}

export async function TrialImportExport(params: {
  dataId: any;
  zcbfid: any;
  tempPath: any;
  accountDatelist: any; Trial: []
  configExportTitleLength: number;
}) {

  let importdata = (arr_table: string[], table: string) => {
    return new Promise(async (resolve, reject) => {
      PubSub.publish('call_progress_import', { data: 41, msg: `${table}导入中`, count: params.configExportTitleLength })

      await templateImport({ type: "fs", dbName: params.zcbfid, dataId: params.dataId, tableNames: arr_table, templateFile: `${params.tempPath}Auditdg-fs.db`, opt: { duplicate: "cover" } })

      resolve(true)

    })
  }
  let arr: any[] = []

  if (params.Trial.filter((a: any) => a.selected).length) {

    // 选中的导入
    params.Trial.filter((a: any) => a.selected).map((a: any) => {


      if (a.selected && a.name == "未审财务报表") {
        let noAudit = ['未审财务报表-负债表', '未审财务报表-利润表', '未审财务报表-现金流补充资料表', "未审财务报表-现金流量表", "未审财务报表-资产表"]
        arr = noAudit
        // arr.push(importdata(noAudit,"未审财务报表"))

      }
      if (a.selected && a.name == "审定财务报表") {
        let adiut = ['审定财务-负债表',
          '审定财务-利润表',
          '审定财务-所有者权益变动表_本年',
          '审定财务-所有者权益变动表_上年',
          '审定财务-现金流补充资料表',
          '审定财务-现金流量表',
          '审定财务-资产减值准备情况表',
          '审定财务-资产表',]
        arr.push(...adiut)

      }
      if (a.selected && a.name == "试算平衡表") {
        let shisuandiut: string[] = []
        params.accountDatelist.forEach((a: any) => {
          shisuandiut.push(`${a.Data_ID}_试算平衡-负债表_期初`)
          shisuandiut.push(`${a.Data_ID}_试算平衡-负债表_期末`)
          shisuandiut.push(`${a.Data_ID}_试算平衡-利润表_本期`)
          shisuandiut.push(`${a.Data_ID}_试算平衡-利润表_上期`)
          shisuandiut.push(`${a.Data_ID}_试算平衡-所有者权益变动表_本年`)
          shisuandiut.push(`${a.Data_ID}_试算平衡-所有者权益变动表_上年`)
          shisuandiut.push(`${a.Data_ID}_试算平衡-现金补充资料表_本期`)
          shisuandiut.push(`${a.Data_ID}_试算平衡-现金补充资料表_上期`)
          shisuandiut.push(`${a.Data_ID}_试算平衡-现金流量表_本期`)
          shisuandiut.push(`${a.Data_ID}_试算平衡-现金流量表_上期`)
          shisuandiut.push(`${a.Data_ID}_试算平衡-资产表_期初`)
          shisuandiut.push(`${a.Data_ID}_试算平衡-资产表_期末`)
          shisuandiut.push(`${a.Data_ID}_试算平衡-资产减值准备情况表`)
        })
        arr = [...arr, ...shisuandiut]
      }


    })
  }
  if (arr.length) {
    await importdata(arr, "财务报表")
  }


}
